package com.example.demo.service;

import com.example.demo.dao.ArticleRepository;
import com.example.demo.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {
    @Autowired
    private ArticleRepository articleRepository;

    public void saveOrUpdate(Article article) {
        articleRepository.save(article);
    }

    public void delete(Integer id) {
        articleRepository.deleteById(id);
    }

    public Article get(Integer id) {
        return articleRepository.getOne(id);
    }

    public List<Article> getAll() {
        return articleRepository.findAll();
    }

    public Page<Article> getPage(Pageable pageable) {
        return articleRepository.findAll(pageable);
    }
    public List<Article> getByTitle(String title) {
        return articleRepository.findByTitleContaining(title);
    }

    public List<Article> getAll2(String title, String body) {
        return articleRepository.query(title, body);
    }
}
